﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Rodunu.Business.Models.Movies;
using System.IO;

namespace Rodunu.Clients.WPF.Collection.Forms
{
    /// <summary>
    /// Interaction logic for NotesForm.xaml
    /// </summary>
    public partial class NotesForm : UserControl
    {
        private Title _movie;

        public Title Movie
        {
            get
            {
                if (_movie == null)
                    _movie = new Title();
                var textRange = new TextRange(NoteTextBox.Document.ContentStart,
                                             NoteTextBox.Document.ContentEnd);
                var memoryStream = new MemoryStream();
                textRange.Save(memoryStream, DataFormats.Text);
                _movie.Plot = ASCIIEncoding.Default.GetString(memoryStream.ToArray());
                return _movie;
            }
            set
            {
                var textRange = new TextRange(NoteTextBox.Document.ContentStart,
                                       NoteTextBox.Document.ContentEnd);
                textRange.Text = value.Plot ?? string.Empty;
                _movie = value;
            }
        }

        public NotesForm()
        {
            InitializeComponent();
        }
    }
}
